#include<bits/stdc++.h>
using namespace std;
int n,t;
int clr[1000005],a[200005],ans;
void dfs(int x){
  if(x>n){
    int sum=0;
    int lb=0,lr=0;
    for(int i=1;i<=n;i++){
      if(clr[a[i]]==0){
        if(lb==a[i])
          sum+=a[i];
        lb=a[i];
      }
      else{
        if(lr==a[i])
          sum+=a[i];
        lr=a[i];
      }
    }
    ans=max(ans,sum);
    return ;
  }
  clr[x]=1;
  dfs(x+1);
  clr[x]=0;
  dfs(x+1);
}
int main(){
  freopen("color.in","r",stdin);
  freopen("color.out","w",stdout);
  cin>>t;
  while(t--){
    ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
      cin>>a[i];
    dfs(1);
    cout<<ans<<endl;
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
